<template>
  <div class="region">
    <div class="content">
      <div class="left">地区：</div>
      <ul>
        <li :class="{active:activeFlag==''}" @click="changeActive('')">全部</li>
        <li v-for="index in regionArr" :class="{active:activeFlag==index.value}" :key="index.value"  @click="changeActive(index.value)">{{ index.name }}</li>
      </ul>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reqHospitalAndRegion } from "@/api/home/index";
import { onMounted , ref} from "vue";
import type { HospitalLevalAndRegionResponseData } from "@/api/home/type";
// 获取地区数组
onMounted(()=>{
  getRegion()
})
// 控制高亮的数据
let activeFlag=ref<string>('')
// 储存地区数据
let regionArr=ref<any>([]);
// 获取地区的方法
const getRegion=async ()=>{
  let result:HospitalLevalAndRegionResponseData=await reqHospitalAndRegion('Beijin')
  if(result.code==200){
    regionArr.value=result.data
  }
}
// 控制高亮的方法
const changeActive=(value:string)=>{
  activeFlag.value=value;
  $emit('getRegion',value)
}
let $emit=defineEmits(['getRegion'])
</script>
<style lang="scss" scoped>
.region {
  color: #7f7f7f;
  margin-top: 10px;
  .content {
    display: flex;
    .left {
      margin-left: 10px;
      width: 55px;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 10px;
        margin-bottom: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>
